home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / ubas830.zip / MALM.EXE / FERMAT.UB < prev    next >
Text File  |  1990-08-22  |  662b  |  19 lines

  1.    10   *Fermat(A,Ubnd,&F,&G)
  2.    20   ' Fermat method of factoring.  Factors are returned in f and g.
  3.    30   ' F and G will be -1 or 0 if failure.
  4.    40   ' Modeled on the Pascal version.  20 April 1990.
  5.    45   '
  6.    50   local T,U,V,S,C=0
  7.    60   if or{A<1,even(A)} then F=0:G=0:return endif
  8.    70   T=isqrt(A)
  9.    80   if res=0 then F=T:G=T:return endif
  10.    90   inc T:U=2*T+1:V=1:S=T*T-A
  11.   100   while and{S<>0,C<Ubnd}
  12.   110   inc C
  13.   120   if S<0 then S+=U:U+=2 else
  14.   130   :while (S>0)S-=V:V+=2 wend endif
  15.   140   wend
  16.   150   if (C>=Ubnd) then F=-1:G=-1:else
  17.   160   :F=(U+V-2)\2:G=(U-V)\2 endif
  18.   170   return ' End of subroutine Fermat
  19.